export default class {
    constructor(option) {
        this.interval = option.interval;
        this.infinite = option.infinite;
        this.content = $(option.content);
        this.run();
        this.handle();
        this.time = 0
    }

    run() {

        let runSlider = setInterval(()=> {
            if (this.time < 2) {
                ++this.time;
            } else {
                this.time = 0;
                if (!this.infinite) {
                    clearInterval(runSlider);
                }
            }
            this.curSlider(this.time);

        }, this.interval)
    }

    handle() {
        var that = this;
        this.content.find('ol li').click(function (e) {
            let curTime = $(e.currentTarget).attr('data-id');
            that.curSlider(curTime);
            that.time = curTime;
        })
    }

    curSlider(num) {
        this.content.find('ul').css('top', -100 * num + 'px');
        this.content.find('ol li').removeClass('active');
        this.content.find('li[data-id|=' + num + ']').addClass('active');
    }
}
